import Vue from 'vue'
import VueRouter from 'vue-router'
import login from './routes/login'
/* import notFind from './routes/404' */
import admin from './routes/admin'
import store from '@/store'

Vue.use(VueRouter)

const routes = [
  admin,
  /* notFind, */
  ...login
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//全局前置守卫
router.beforeEach((to,from,next) => {
  if(to.path !== '/login'){
    if(store.getters.token === ''){
      next({ path:'/login',replace:true })
    }else{
      next()
    }   
  }else{
    next()
  }
})

export default router
